package jdk8.lambda;

import java.util.function.Supplier;

public class SupplierDemo {

	public static void main(String[] args) {
		//
		Supplier<Double> sd = new Supplier<Double>() {
			
			@Override
			public Double get() {
				//
				return Math.random();
			}
		};
		//调用
		System.out.println(sd.get());
		//
		System.out.println("----------- 使用 Lambda 表达式来创建 Supplier的实例");
		sd = () -> Math.random();
		//方法引用
		//sd = Math::random;
		
		System.out.println(sd.get());
		//
		Supplier<String> sdStr = () -> {
			final String original = "abcdefghijklmnopqrstuvwxyz";
			StringBuilder builder = new StringBuilder();
			for(int i = 0;i<8;i++) {
				builder.append(original.charAt((int)(Math.random() * 26)));
			}
			//
			return builder.toString();
		};
		//
		System.out.println(sdStr.get());
	}
}
